package com.zhang.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Pattern;
import java.time.LocalDate;
import java.util.List;

/**
 * 订单实体类
 */
@Data
@NoArgsConstructor
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
public class OrderBean {
    /**订单id*/
    private int orderId;
    /**收货人*/
    @Pattern(regexp = "[\\u4e00-\\u9fa5\\w]{1,20}",message = "只能是1-20位字符数字字母")
    private String person;
    /**订单状态*/
    private String status = "未发货";
    /**收货地址*/
    @Pattern(regexp = "[\\u4e00-\\u9fa5\\w]{5,}",message = "只能XX省XX市XX区")
    private String address;
    /**收货电话*/
    @Pattern(regexp = "1[3456]\\d{9}",message = "只能是以13,14,15开头的11位数字")
    private String phone;
    /**下单时间*/
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate time = LocalDate.now();
    /**所属用户*/
    private UserBean userBean;
    /**订单明细*/
    private List<OrderInfoBean> orderInfoBeans;
    /**订单总价*/
    private int total;


    public OrderBean(String person, String phone, String address, int userId, int total) {
        this.person = person;
        this.phone = phone;
        this.address = address;
        this.userBean = new UserBean();
        userBean.setUserId(userId);
        this.total = total;
    }

    @Override
    public String toString() {
        return "OrderBean{" +
                "orderId=" + orderId +
                ", person='" + person + '\'' +
                ", phone='" + phone + '\'' +
                ", status='" + status + '\'' +
                ", address='" + address + '\'' +
                ", time=" + time +
                ", userBean=" + userBean +
                ", orderInfoBeans=" + orderInfoBeans +
                ", total=" + total +
                '}' + "\n";
    }
}
